package com.eyedsion.his.web.service.sycndata;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author 彭长云
 * @Description:
 * @date 2019/1/19 10:15
 */
@Service
public class CommonService {

    @Autowired
    private RedisTemplate redisTemplate;

    public boolean hasLock(String lockName){
        Boolean hasLock = redisTemplate.hasKey(lockName);
        if(!hasLock){
            redisTemplate.opsForValue().set(lockName,"");
            redisTemplate.expire(lockName,22, TimeUnit.HOURS);
        }
        return hasLock;
    }

    public void removeLock(String lockName){
        redisTemplate.delete(lockName);
    }
}
